package pl.enigmatic.test;

import java.awt.BorderLayout;
import java.awt.GridLayout;


public class ButtonsControllerPanel extends NamedPanel {

	/** */
	private static final long serialVersionUID = 1L;

	private ButtonsControllerPanel(final String name, final int btns) {
		super(name);
		if (btns > 0) {
			final int size = (int) Math.ceil(Math.sqrt(btns));
			setLayout(new GridLayout(size, size, 5, 5));
		} else {
			setLayout(new BorderLayout());
		}
	}

	public ButtonsControllerPanel(final String name, final Action... actions) {
		this(name, actions.length);
		int i = 0;
		for (final Action a : actions) {
			add(new Button(a, i++));
		}
	}

	public ButtonsControllerPanel(final String name, final Action action, final String... captions) {
		this(name, captions.length);
		int i = 0;
		for (final String c : captions) {
			add(new Button(action, c, i++));
		}
	}

	public ButtonsControllerPanel(final Action... actions) {
		this(null, actions);
	}

	public ButtonsControllerPanel(final Action action, final String... captions) {
		this(null, action, captions);
	}
}
